
package com.jl.cloud.consumer.service.kafka;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;


/**
 * kafka 生产者
 *
 * @author lu.chen@eslink.cc
 */
@Component
@Slf4j
public class KafkaProducer{

    @Value("${kafka.topic.defaultTopic}")
    private String topic;

    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    /**
     * 发送消息
     */
    public void send(String msg) {
        send("",topic, msg);
    }

    public void send(String key, String topic, String msg) {
        kafkaTemplate.send(topic, key, msg);

    }

}
